﻿//=======================================================
// 作者：KingSley
// 描述：控制器，定义应用程序行为，用户动作映射成模型更新，选择响应的视图
//=======================================================
using UnityEngine;
using System.Collections;

namespace MVC
{ 
    public class PlayerMsgController : MonoBehaviour
    {
        public static PlayerMsgController controller;

        private int levelUpValue = 20;

        void Awake()
        {
            controller = this;
        }

        void Start()
        {
            //PlayerMsgModel.GetMod().PlayerLevel = 1;
            //PlayerMsgModel.GetMod().PlayerExperience = 0;
            //PlayerMsgModel.GetMod().PlayerFullExperience = 100;
            //PlayerMsgModel.GetMod().GoldNum = 0;
        }

        /// <summary>
        /// 提升经验按钮点击事件
        /// </summary>
        public void OnExperienceUpButtonClick()
        {
            // 仅有在连接数据库后才能够对数据进行修改
            if (PlayerMsgDB.GetDB().IsCon == true) 
            {
                PlayerMsgModel.GetMod().PlayerExperience += levelUpValue;
                if (PlayerMsgModel.GetMod().PlayerExperience
                    >= PlayerMsgModel.GetMod().PlayerFullExperience)
                {
                    PlayerMsgModel.GetMod().PlayerLevel += 1;
                    PlayerMsgModel.GetMod().PlayerFullExperience +=
                        200 * PlayerMsgModel.GetMod().PlayerLevel;
                    levelUpValue += 20;
                    if (PlayerMsgModel.GetMod().PlayerLevel % 3 == 0)
                    {
                        PlayerMsgModel.GetMod().GoldNum +=
                            100 * PlayerMsgModel.GetMod().PlayerLevel;
                    }
                }
                // 对数据发生的修改同步到数据库当中
                PlayerMsgDB.GetDB().UpdateDB();
            }
        }
    }
}
